package com.lyxs916.testlibrary.viewpagerframent;


import com.lyxs916.appbaselibrary.core.http.BaseHttpCallback;
import com.lyxs916.appbaselibrary.core.presenter.BasePresenter;
import com.lyxs916.common.HeadType;
import com.lyxs916.common.HostType;
import com.lyxs916.httpresponse.HttpResult;
import com.lyxs916.network.BaseHttpRequest;
import com.lyxs916.network.HttpCallBack;
import com.lyxs916.requestbody.HttpRequestParam;

import java.util.List;

/**
 * 说明:陪护-我的订单
 * 360621904@qq.com 杨阳 2017/3/24  14:19
 */
public class OrderPresenter extends BasePresenter<OrderParentInterfaces.IOrder> {
    /**
     * 用户浏览自己的护理订单
     * 接口：/nurse/orders.action
     * 参数 	约束	说明
     * code	必选 	单一用户唯一码,用户登录接口返回
     * token	必选	单一用户短时段内的请求令牌,用户登录接口返回
     * 参数说明 (默认字符串类型)
     * 参数 	约束	说明
     * state	必选,int	要查询的订单状态,
     * 1:待服务; 2:服务中;4:已完成; 7:待接单
     * type	可选,int	护理类型，1-全天、2-钟点
     * start	必选,int	分页参数，开始位置，以0为起始
     * size	必选,int	分页参数，单页展示数量
     *
     * @param isFirst
     * @param state   收藏的护理人员类型，1-全天工，2-钟点工
     */
    public void getHttpData(int type, final boolean isFirst, int state) {


        HttpCallBack.Builder buider = new BaseHttpCallback.BaseBuilder(mvpView)
                .setShowLoading(mvpView.getBaseActivity(), isFirst)
                .setCancelable(true)
                .setHint("正在加载...")
                .setHttpHead(HeadType.LOGIN_HEAD)
                .setShowDefeatView(isFirst, null)
                .setHostType(HostType.TYPE_DEFAULT);

        if (isFirst) {
            mvpView.clearPagingData();
        }

        final BaseHttpCallback httpCallBack = new BaseHttpCallback<HttpResult<NurserOrderdData>>(buider) {
            @Override
            public void onSuccess(final HttpResult<NurserOrderdData> result) {
                super.onSuccess(result);
                if (result != null) {
                    try {
                        mvpView.getHttpData(result.getData().getTotal(), (List<NurserOrderdData.ObjsBean>) mvpView.getValidData(result.getData().getObjs()));

                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }
        };

//
//        Map<String, String> map = new HashMap<>();
//        map.put("state", 4 + "");
//        map.put("start", mvpView.getPageindex() - 1 + "");
//        map.put("size", mvpView.getPageindex() * mvpView.getPageCount() + "");
//        BaseHttpRequest.executePost(httpCallBack, "/nurse/orders.action", map);


        HttpRequestParam param=new HttpRequestParam();
        param.addParam("state",4);
        param.addParam("start",mvpView.getPageindex() - 1 );
        param.addParam("size",mvpView.getPageindex() * mvpView.getPageCount());

        BaseHttpRequest.executePost(httpCallBack, "/nurse/orders.action", param);


    }
}
